﻿using Microsoft.AspNetCore.Mvc;
using Senparc.Weixin.MP.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WhoIsUnderCover.Models;

namespace WhoIsUnderCover.Controllers
{
    public class LogicController: Controller
    {

        private readonly UnderCoverContext _context;

        public LogicController(UnderCoverContext context)
        {
            _context = context;
        }
        public void CreateRoom(string openId)
        {
            
        }

        public void CreateUser(string openId)
        {
           var wxuser= _context.wxUsers.Where(x => x.OpenId == openId).FirstOrDefault();
            if(wxuser==null)
            {
                var user = new WxUser
                {
                    OpenId = openId,
                    SubscribeDt = DateTime.Now,
                    RecStatus=1,
                    RecCreateDt=DateTime.Now
                };
                _context.Add(user);
            }
            else
            {
                wxuser.SubscribeDt = DateTime.Now;
                _context.SaveChanges();
            }
        }
    }
}
